# coding: utf-8
from __future__ import  unicode_literals
import pandas as pd
from sklearn.metrics import f1_score
import fasttext


x_train = pd.read_csv('./data/train_set.csv',sep='\t', nrows=15000) # nrows=200
x_train['label_ft'] = '__label__' + x_train['label'].astype(str)
x_train[['text','label_ft']].iloc[:-5000].to_csv('./data/train.csv', index=None, header=None, sep='\t')

print(x_train.head())


model = fasttext.train_supervised('./data/train.csv', lr=1.0, wordNgrams=2, verbose=2, minCount=1, epoch=25, loss="hs")
x_train_pred = [model.predict(x)[0][0].split('__')[-1] for x in x_train.iloc[-5000:]['text']]
print(f1_score(x_train['label'].values[-5000:].astype(str), x_train_pred, average='macro'))